package com.campus.delivery;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.campus.common.mybatis.entity.IntegerIdBaseEntity;

import java.io.File;
import java.util.Collections;


public class MybatisPlusGenerator {
	/**
	 * 作者 开发人员姓名
	 */
	private final static String author = "ZhaoYuJie";
	private final static String parentPackage = "com.campus.delivery";

	private final static String modelPath = System.getProperty("user.dir")+ File.separator+"campus-delivery";
	/**
	 * 本次代码生成的表名
	 */
//	private final static String[] tableName = {
//			"address", "banner", "canteen", "category", "coupon", "delivery", "delivery_apply", "delivery_user", "feedback", "goods", "goods_category", "goods_spec_group", "goods_spec_option", "location", "merchant", "merchant_apply", "merchant_business_hours", "merchant_category", "merchant_user", "order", "order_comment", "order_goods", "payment_method", "points_exchange", "points_goods", "points_record", "user", "user_coupon"
//	};
	private final static String[] tableName = {"notice"};

//	private final static String[] ignoreColumns = {"ID", "CREATOR_ID", "CREATE_TIME", "CREATOR_NAME", "UPDATOR_ID", "UPDATE_TIME", "UPDATOR_NAME", "DEL_FLAG"};

	//private final static Class<?> superClass = LongIdLogicEntity.class;
	private final static Class<?> superClass = IntegerIdBaseEntity.class;

	public static void main(String[] args) {
		FastAutoGenerator.create(
						"jdbc:mysql://localhost:3306/campus",
						"root",
						"123456")
				// 全局配置
				.globalConfig(builder -> {
					builder.author(author) // 设置作者
							.disableServiceInterface()
							.enableSwagger() // 开启 swagger 模式
							.outputDir(modelPath + "/src/main/java"); // 指定输出目录
				})
				// 包配置
				.packageConfig(builder -> {
					builder.parent(parentPackage) // 设置父包名
						//	.service("service")       //service
							.serviceImpl("service")
//							.mapper("mapper")
//							.xml("mapper")
//							.entity("bean.entity")
							.pathInfo(Collections.singletonMap(OutputFile.xml, modelPath + "/src/main/resources/mapper")); // 设置mapperXml生成路径;
				})
				//表的配置
				.strategyConfig(builder -> {
					builder.addInclude(tableName)// 设置需要生成的表名
//							.addTablePrefix("tb_", "gms_") // 设置过滤表前缀
							.controllerBuilder()
							.enableRestStyle()
							.formatFileName("%sController")
							.serviceBuilder()//service策略配置
							//.formatServiceFileName("%sService")
							.formatServiceImplFileName("%sService")
							.entityBuilder()// 实体类策略配置
							.formatFileName("%s")
//							.idType(IdType.AUTO)//主键策略 雪花算法自动生成的id
//							.addTableFills(new Column("create_time", FieldFill.INSERT)) // 自动填充配置
//							.addTableFills(new Property("update_time", FieldFill.INSERT_UPDATE))
							.enableActiveRecord()
							.enableTableFieldAnnotation()
//							.addIgnoreColumns(ignoreColumns)
							.superClass(superClass)
							.enableLombok() //开启lombok
//							.logicDeleteColumnName("DEL_FLAG")// 说明逻辑删除是哪个字段
							.mapperBuilder()// mapper策略配置
							.formatMapperFileName("%sMapper")
//							.enableMapperAnnotation()//@mapper注解开启
							.formatXmlFileName("%sMapper");
				})
				.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
				.execute();
		System.out.println("成功了");
	}


}
